import request from '@/modules/index/utils/request';
import { downloadFile } from '@/utils/common';
import { Message } from 'element-ui';

const store = {
  actions: {
    // 分页查询我发布的任务
    async openAbilityPlatformPredictTaskSearch (context, params) {
      const data = await request({
        url: '/platform/predict-task/search',
        method: 'post',
        data: params
      });
      return data;
    },
    // 下载分析结果
    async openAbilityPlatformPredictTaskIdDownLoadResult(context, params) {
      const data = await request({
        url: `/platform/predict-task/${params.id}/downLoadResult`,
        method: 'get',
        params: params,
        responseType: 'blob'
      });
      if (!data.data) {
        Message.error("下载文件失败");
        return;
      }
      downloadFile(data);
    },
    // 新增任务-上传文件
    async openAbilityPlatformPredictTaskUpload (context, params) {
      const data = await request({
        url: `/platform/predict-task/upload`,
        method: 'post',
        data: params,
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      });
      return data;
    },
    // 多条文本
    async openAbilityPlatformPredictTaskMuticommet (context, params) {
      const data = await request({
        url: '/platform/predict-task/muticommet',
        method: 'post',
        data: params
      });
      return data;
    },
    // 单条文本
    async openAbilityPlatformPredictTaskOnecommet (context, params) {
      const data = await request({
        url: '/platform/predict-task/onecommet',
        method: 'post',
        data: params
      });
      return data;
    },
    // 单条文本-关键词获取
    async openAbilityPlatformPredictTaskOneExtraComment (context, params) {
      const data = await request({
        url: '/platform/predict-task/oneExtraComment',
        method: 'post',
        data: params
      });
      return data;
    },

    // 单个图片
    async openAbilityPlatformPredictTaskOcrSingle (context, params) {
      const data = await request({
        url: `/platform/predict-task/ocr-single`,
        method: 'post',
        data: params,
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      });
      return data;
    },
    // 多个图片
    async openAbilityPlatformPredictTaskIdOcrMulti (context, params) {
      const data = await request({
        url: `/platform/predict-task/${params.id}/ocr-multi`,
        method: 'post',
        params: params
      });
      return data;
    },
    // 下载模板文件
    async openAbilityPlatformPredictTaskGetFile (context, params) {
      const data = await request({
        url: '/platform/predict-task/getFile',
        method: 'post',
        params: params,
        responseType: 'blob'
      });
      if (!data.data) {
        Message.error("下载文件失败");
        return;
      }
      downloadFile(data);
    },
  }
};

export default store;
